package com.example.arithmeticleetcode.leetcode.dec;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-12-14 11:58
 **/
public class Demo09 {

    public static int numberOfMatches(int n) {
        if (n == 1) return 0;
        int dividValue = n >> 1;
        int remain = n & 1;
        int sum = dividValue + remain;
        return dividValue + numberOfMatches(sum);
    }

    public static int numberOfMatches2(int n) {
        int sum = 0;
        while (n > 1) {
            int dividValue = (n >> 1);
            sum += dividValue;
            n = dividValue + (n & 1);
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(numberOfMatches(7));
        System.out.println(numberOfMatches(14));
        System.out.println(numberOfMatches2(7));
        System.out.println(numberOfMatches2(14));
    }
}
